//
//  YQLPictureCollectionView.swift
//  YQL_WeiBo
//
//  Created by apple on 2016/11/17.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

let pictureCellID: String = "PictureCell"
class YQLPictureCollectionView: UICollectionView {

    
    var pictureArr: [YQLPictureInfo]? {
        
        didSet {
            self.reloadData()
        }
    }
    
    // MARK: - 唤醒XIB的方法中配置collectionView
    override func awakeFromNib() {
        //注册
        let nib = UINib.init(nibName: "YQLPictureCell", bundle: nil)
        self.register(nib, forCellWithReuseIdentifier: pictureCellID)
        //设置数据源代理
        self.dataSource = self
    }
    

}
// MARK: - 分类
extension YQLPictureCollectionView: UICollectionViewDataSource {
    
    // MARK: - 数据源方法
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.pictureArr?.count ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: pictureCellID, for: indexPath) as! YQLPictureCell
        let model = self.pictureArr?[indexPath.item]
        cell.model = model
        
        return cell
    }
    
    
}
